/**
 *  *2010-5-19 下午08:45:58  add 
 */
package com.base.myproject.client.HR.Salary;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BaseStoreEvent;
import com.base.myproject.client.busi.BaseStoreListener;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.busi.BO.SetGetValue;
import com.base.myproject.client.busi.BaseStoreEvent.EventType;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.system.Env;
import com.base.myproject.client.tools.CommandSyncContainer;
import com.base.myproject.client.tools.CommandSyncGetModelDatas;
import com.base.myproject.client.tools.CommandSyncMakeCode;
import com.base.myproject.client.tools.CommandSyncReturnObject;
import com.base.myproject.client.ui.BaseFormPanel;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.store.Store;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.form.StoreFilterField;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

/**
 * 
 * @author Administrator 2010-5-19 javazgw@gmail.com
 */
public class MakeSalary extends BaseJDBCPanel {
	Button addto = new Button("添加");
	Button delto = new Button("移除");
	Button prequery = new Button("预查工资");
	Button savesalary = new Button("储存结果");
	Button save = new Button("保存");
	public MakeSalary() {
		init();
	}

	public void init() {

		this.add(initWeigetx());
		addto.addListener(Events.Select, getListener());
		delto.addListener(Events.Select, getListener());
		prequery.addListener(Events.Select, getListener());
		savesalary.addListener(Events.Select, getListener());
		save.addListener(Events.Select, getListener());
	}

	public void complete() {
		super.complete();
		ttiratify.setText("提交确认");
		getToolbarll().add(ttiratify);
		getToolbarll().add(prequery);
	}

	private Widget initWeigetx() {
		HorizontalPanel h = new HorizontalPanel();
		h.add(addto);
		h.add(delto);
		ContentPanel cp = new ContentPanel();
		cp.setHeaderVisible(false);
		TableLayout tl = new TableLayout(2);
		TableData td = new TableData();
		td.setRowspan(2);
		td.setColspan(1);

		td.setHorizontalAlign(HorizontalAlignment.LEFT);
		td.setVerticalAlign(VerticalAlignment.TOP);

		TableData td1 = new TableData();
		td1.setRowspan(1);
		td1.setColspan(1);
		td1.setHorizontalAlign(HorizontalAlignment.LEFT);
		td1.setVerticalAlign(VerticalAlignment.TOP);
		
		
		TableData td2 = new TableData();
		td2.setRowspan(1);
		td2.setColspan(2);
		td2.setHorizontalAlign(HorizontalAlignment.LEFT);
		td2.setVerticalAlign(VerticalAlignment.TOP);

		cp.setLayout(tl);

		FieldSet fs = new FieldSet();
		fs.setHeading("薪金类型");
		fs.add(create_hr_Salary_Item_Grid());
		cp.add(fs, td);
//		cp.add(create_zy_Grid(), td1);
//		cp.add(create_zyzk_Grid(), td1);
//		cp.add(create_systeminfo_Grid(), td1);
		FieldSet fs2 = new FieldSet();
		fs2.setHeading("可以选择人员");
		fs2.add(createBcodePanel());
		cp.add(fs2, td1);

		
		FieldSet fs3 = new FieldSet();
		fs3.setHeading("已选择人员");
		fs3.add(createMakeBcodeGrid());
		
		cp.add(fs3, td1);
		
//		cp.add(prequery, td2);
//		cp.add(savesalary, td2);
//		cp.add(new Label(""), td2);
//		HorizontalPanel h2 = new HorizontalPanel();
//		h2.add(prequery);
		//h2.add(savesalary);
		VerticalPanel v = new VerticalPanel();
		
		//v.add(h2);
		//v.add(createSalaryGrid());
		
		cp.add(v, td2);
		
/*		HorizontalPanel h = new HorizontalPanel();
		 h.add(addto);
		
		 
		 HorizontalPanel h2 = new HorizontalPanel();
		
		 h2.add(prequery);
		 h2.add(savesalary);
		 
		 HorizontalPanel h3 = new HorizontalPanel();
		 h3.add(createBcodePanel());
		 h3.add(createMakeBcodeGrid());
		VerticalPanel v = new VerticalPanel();
		v.add(create_hr_Salary_Item_Grid());
		v.add(createBcodePanel());
		v.add(createMakeBcodeGrid());
		v.add(createSalaryGrid());
		v.add(h);*/
		return cp;
	}

	BaseStore<BusiObject> hr_Salary_Item_store = null;

	BaseStore<BusiObject> get_hr_Salary_Item_Store() {
		if (hr_Salary_Item_store == null) {
			create_hr_Salary_Item_Store();
		}
		return hr_Salary_Item_store;
	}

	BaseStore<BusiObject> create_hr_Salary_Item_Store() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("code");
		type.getField("code").setType(String.class);
		type.addField("desc_cn");
		type.getField("desc_cn").setType(String.class);
		type.addField("desc_en");
		type.getField("desc_en").setType(String.class);
		type.addField("ifrate");
		type.getField("ifrate").setType(Boolean.class);
		type.addField("ifAttendance");
		type.getField("ifAttendance").setType(Boolean.class);
		type.addField("iftax");
		type.getField("iftax").setType(Boolean.class);
		type.addField("status");
		type.getField("status").setType(String.class);
		type.addField("dc");
		type.getField("dc").setType(Boolean.class);
		type.addField("vprepare");
		type.getField("vprepare").setType(String.class);
		type.addField("modifydate");
		type.getField("modifydate").setType(Date.class);
		type.addField("createdate");
		type.getField("createdate").setType(Date.class);
		StoreInfo info = new StoreInfo();
		info.setTablename("hr_Salary_Item");
		info.setKeyname(new String[] { "icode" });
		info.setSql("select * from hr_Salary_Item");
		// info.setParent(mainstore);// 关联主表
		// info.setLinkparentcolumns(new String[] { "icode" }); // 关联主表字段
		// info.setLinkparent_chile_columns(new String[] { "upicode" });//
		// 关联主表字段
		hr_Salary_Item_store = new BaseStore<BusiObject>(type, info);
		return hr_Salary_Item_store;
	}

	BaseGrid<BusiObject> hr_Salary_Item_grid = null;

	BaseGrid<BusiObject> create_hr_Salary_Item_Grid() {
		CheckBoxSelectionModel<BusiObject> cbs = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());

		// ColumnConfig C1 = new ColumnConfig("icode", "icode", 80);
		// columns.add(C1);
		ColumnConfig C2 = new ColumnConfig("code", "编码", 80);
		columns.add(C2);
		ColumnConfig C3 = new ColumnConfig("desc_cn", "中文描述", 80);
		columns.add(C3);
		ColumnConfig C4 = new ColumnConfig("desc_en", "英文描述", 80);
		columns.add(C4);
		// ColumnConfig C5 = new ColumnConfig("ifrate", "ifrate", 80);
		// columns.add(C5);
		// ColumnConfig C6 = new ColumnConfig("ifAttendance", "ifAttendance",
		// 80);
		// columns.add(C6);
		// ColumnConfig C7 = new ColumnConfig("iftax", "iftax", 80);
		// columns.add(C7);
		// ColumnConfig C8 = new ColumnConfig("status", "status", 80);
		// columns.add(C8);
		// ColumnConfig C9 = new ColumnConfig("dc", "dc", 80);
		// columns.add(C9);
		// ColumnConfig C10 = new ColumnConfig("vprepare", "vprepare", 80);
		// columns.add(C10);
		// ColumnConfig C11 = new ColumnConfig("modifydate", "modifydate", 80);
		// columns.add(C11);
		// ColumnConfig C12 = new ColumnConfig("createdate", "createdate", 80);
		// columns.add(C12);

		ColumnModel cm = new ColumnModel(columns);
		hr_Salary_Item_grid = new BaseGrid<BusiObject>(get_hr_Salary_Item_Store(), cm,
				false, false);
		cbs.setSelectionMode(SelectionMode.MULTI);
		hr_Salary_Item_grid.setSelectionModel(cbs);
		hr_Salary_Item_grid.setHeight(405);
		hr_Salary_Item_grid.setWidth(200);
		hr_Salary_Item_grid.addPlugin(cbs);
		return hr_Salary_Item_grid;
	}

/*	BaseStore<BusiObject> zy_store = null;

	BaseStore<BusiObject> get_zy_Store() {
		if (zy_store == null) {
			create_zy_Store();
		}
		return zy_store;
	}

	BaseStore<BusiObject> create_zy_Store() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("code");
		type.getField("code").setType(String.class);
		type.addField("name");
		type.getField("name").setType(String.class);

		StoreInfo info = new StoreInfo();
		info.setTablename("dictionary");
		info.setKeyname(new String[] { "icode" });
		info.setSql("select * from dictionary where type='zy'");
		// info.setParent(mainstore);// 关联主表
		// info.setLinkparentcolumns(new String[] { "icode" }); // 关联主表字段
		// info.setLinkparent_chile_columns(new String[] { "upicode" });//
		// 关联主表字段
		zy_store = new BaseStore<BusiObject>(type, info);
		return zy_store;
	}

	BaseGrid zy_grid = null;

	BaseGrid create_zy_Grid() {
		CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());

		ColumnConfig C2 = new ColumnConfig("code", "code", 80);
		columns.add(C2);
		ColumnConfig C3 = new ColumnConfig("name", "name", 80);
		columns.add(C3);

		ColumnModel cm = new ColumnModel(columns);
		zy_grid = new BaseGrid(get_zy_Store(), cm, false, false);
		cbs.setSelectionMode(SelectionMode.MULTI);
		zy_grid.setSelectionModel(cbs);
		zy_grid.setHeight(200);
		zy_grid.setWidth(200);
		return zy_grid;
	}
*/
	/*BaseStore<BusiObject> zyzk_store = null;

	BaseStore<BusiObject> getzyzkStore() {
		if (zyzk_store == null) {
			create_zyzk_Store();
		}
		return zyzk_store;
	}

	BaseStore<BusiObject> create_zyzk_Store() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("code");
		type.getField("code").setType(String.class);
		type.addField("name");
		type.getField("name").setType(String.class);

		StoreInfo info = new StoreInfo();
		info.setTablename("dictionary");
		info.setKeyname(new String[] { "icode" });
		info.setSql("select * from dictionary where type='zyzk'");
		// info.setParent(mainstore);// 关联主表
		// info.setLinkparentcolumns(new String[] { "icode" }); // 关联主表字段
		// info.setLinkparent_chile_columns(new String[] { "upicode" });//
		// 关联主表字段
		zyzk_store = new BaseStore<BusiObject>(type, info);
		return zyzk_store;
	}

	BaseGrid zyzk_grid = null;

	BaseGrid create_zyzk_Grid() {
		CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());

		ColumnConfig C2 = new ColumnConfig("code", "code", 80);
		columns.add(C2);
		ColumnConfig C3 = new ColumnConfig("name", "name", 80);
		columns.add(C3);

		ColumnModel cm = new ColumnModel(columns);
		zyzk_grid = new BaseGrid(getzyzkStore(), cm, false, false);
		cbs.setSelectionMode(SelectionMode.MULTI);
		zyzk_grid.setSelectionModel(cbs);
		zyzk_grid.setHeight(200);
		zyzk_grid.setWidth(200);
		return zyzk_grid;
	}*/

/*	BaseStore<BusiObject> systeminfostore = null;

	BaseStore<BusiObject> getSysteminfoStore() {
		if (systeminfostore == null) {
			createsysteminfoStore();
		}
		return systeminfostore;
	}

	BaseStore<BusiObject> createsysteminfoStore() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("id");
		type.getField("id").setType(String.class);
		type.addField("name");
		type.getField("name").setType(String.class);
		StoreInfo info = new StoreInfo();
		info.setTablename("null");
		info.setKeyname(new String[] { "icode" });
		info.setSql("Select id,name from systeminfo");
		// info.setParent(mainstore);// 关联主表
		// info.setLinkparentcolumns(new String[] { "icode" }); // 关联主表字段
		// info.setLinkparent_chile_columns(new String[] { "upicode" });//
		// 关联主表字段
		systeminfostore = new BaseStore<BusiObject>(type, info);
		return systeminfostore;
	}

	BaseGrid systeminfo_grid = null;

	BaseGrid create_systeminfo_Grid() {
		CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());

		ColumnConfig C1 = new ColumnConfig("id", "id", 80);
		columns.add(C1);
		ColumnConfig C2 = new ColumnConfig("name", "name", 80);
		columns.add(C2);

		ColumnModel cm = new ColumnModel(columns);
		systeminfo_grid = new BaseGrid(getSysteminfoStore(), cm, false, false);
		
		cbs.setSelectionMode(SelectionMode.MULTI);
		systeminfo_grid.setSelectionModel(cbs);
		systeminfo_grid.setHeight(200);
		return systeminfo_grid;
	}
*/
	BaseStore<BusiObject> bcodestore = null;

	BaseStore<BusiObject> getbcodestore() {
		if (bcodestore == null) {
			createbcodeStore();
		}
		return bcodestore;
	}
	ModelType bcodetype = new ModelType();
	BaseStore<BusiObject> createbcodeStore() {
		
		bcodetype.setRoot("records");
		bcodetype.setRecordName("record");
		bcodetype.setTotalName("totle");
		bcodetype.addField("bcode");
		bcodetype.getField("bcode").setType(String.class);
		bcodetype.addField("bname");
		bcodetype.getField("bname").setType(String.class);
		bcodetype.addField("systemid");
		bcodetype.getField("systemid").setType(String.class);
		
		StoreInfo info = new StoreInfo();
		info.setTablename("null");
		info.setKeyname(new String[] { "icode" });
		info.setSql("Select  bcode,bname,systemid from bcode");
		// info.setParent(mainstore);// 关联主表
		// info.setLinkparentcolumns(new String[] { "icode" }); // 关联主表字段
		// info.setLinkparent_chile_columns(new String[] { "upicode" });//
		// 关联主表字段
		bcodestore = new BaseStore<BusiObject>(bcodetype, info);
		return bcodestore;
	}

	BaseGrid<BusiObject> bcodegrid = null;

	BaseGrid<BusiObject> createBcodeGrid() {
		CheckBoxSelectionModel<BusiObject> cbs = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());

		ColumnConfig C1 = new ColumnConfig("bcode","人员编码",  80);
		columns.add(C1);
		ColumnConfig C2 = new ColumnConfig("bname","人员编码",  80);
		columns.add(C2);
		ColumnConfig C3 = new ColumnConfig("systemid", "组织", 80);
		columns.add(C3);

		ColumnModel cm = new ColumnModel(columns);
		bcodegrid = new BaseGrid<BusiObject>(getbcodestore(), cm, false, false);
		cbs.setSelectionMode(SelectionMode.MULTI);
		
		
		bcodegrid.setSelectionModel(cbs);
		 bcodegrid.setWidth(500);
		bcodegrid.setHeight(160);
		bcodegrid.addPlugin(cbs);
		return bcodegrid;
	}
	
	
	Widget createBcodePanel()
	{
		LayoutContainer bcodelc = new LayoutContainer();
		
		StoreFilterField<BusiObject> field = new StoreFilterField<BusiObject>() {
			@Override
			protected boolean doSelect(Store<BusiObject> store,
					BusiObject parent, BusiObject record, String property,
					String filter) {

			return	Select(store,parent,record,property,filter);
			}

			@Override
			protected void onFilter() {
				super.onFilter();

				// grid.getSelectionModel().select(0);
			}

		};
		field.setAutoWidth(true);
		field.setToolTip("对当前页面进行查找");
		field.bind(getbcodestore());
		
		
		bcodelc.add(createBcodeGrid());
		HorizontalPanel h = new HorizontalPanel();
		field.setWidth(200);
		h.add(new Label("查找："));
		h.add(field);
		h.add(addto);
		h.add(delto);
		bcodelc.add(h);

		return bcodelc;
	}
	/**
	 * 过滤
	 * @param store
	 * @param parent
	 * @param record
	 * @param property
	 * @param filter
	 * @return
	 */
	protected boolean Select(Store<BusiObject> store,
			BusiObject parent, BusiObject record, String property,
			String filter) {
		for (int i = 0; i < bcodetype.getFieldCount(); i++) {

			Object name = record.get(bcodetype.getField(i).getName());
			
			//TODO
			if (name!=null&&name.toString().indexOf(filter.toLowerCase()) != -1) {
				return true;
			}
		}
	
		return false;
	}
	
	BaseStore<BusiObject> makebcodestore = new BaseStore<BusiObject>();
	BaseGrid<BusiObject> makebcodegrid = null;
	/**
	 * 发薪人员，临时表
	 * @return
	 */
	BaseGrid<BusiObject> createMakeBcodeGrid() {
		CheckBoxSelectionModel<BusiObject> cbs = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());

		ColumnConfig C1 = new ColumnConfig("bcode", "人员编码", 80);
		columns.add(C1);
		ColumnConfig C2 = new ColumnConfig("bname", "人员名称", 80);
		columns.add(C2);
		ColumnConfig C3 = new ColumnConfig("systemid", "组织", 80);
		columns.add(C3);
		ColumnModel cm = new ColumnModel(columns);
		makebcodegrid = new BaseGrid<BusiObject>(makebcodestore, cm, false, false);
		cbs.setSelectionMode(SelectionMode.MULTI);
		
		
		makebcodegrid.setSelectionModel(cbs);
		makebcodegrid.setWidth(500);
		makebcodegrid.setHeight(160);
		
		return makebcodegrid;
	}
	BaseStore<BusiObject> salarystore =new  BaseStore<BusiObject>();
	Widget createSalaryGrid()
	{
		
		CheckBoxSelectionModel<BusiObject> cbs = new CheckBoxSelectionModel<BusiObject>();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());

		ColumnConfig C1 = new ColumnConfig("bcode", "人员编码", 80);
		columns.add(C1);
		ColumnConfig C5 = new ColumnConfig("bname", "人员", 80);
		columns.add(C5);
		ColumnConfig C2 = new ColumnConfig("allowanceno_", "薪金类别", 80);
		columns.add(C2);
		ColumnConfig C3 = new ColumnConfig("desc_cn", "描述", 80);
		columns.add(C3);
		ColumnConfig C4 = new ColumnConfig("amount", "金额", 80);
		columns.add(C4);
//		ColumnConfig C5 = new ColumnConfig("icode", "icode", 80);
//		columns.add(C5);
		
		ColumnModel cm = new ColumnModel(columns);
		BaseGrid salarygrid = new BaseGrid(salarystore,cm,false,false);
		
		salarygrid.setHeight(400);
		salarygrid.setWidth(490);
		StoreInfo storeinfo = new StoreInfo();
		storeinfo.setTablename("hr_salary");
		//storeinfo.setTablename("null");
		storeinfo.setKeyname(new String[] { "icode" });
		//storeinfo.setSql("Select  bcode,bname,systemid from bcode");
		salarystore.setStoreinfo(storeinfo);
		return salarygrid;
	}
	
	BaseStore<BusiObject> hr_msalarystore = null;
//储存预查结果
	Dialog createMakeDialog()
	{
		Dialog d = new Dialog();
		d.setHeading("储存结果");
	
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.setTotalName("totle");
		type.addField("icode");
		type.getField("icode").setType(Long.class);
		type.addField("vprepare");
		type.getField("vprepare").setType(String.class);
		type.addField("status");
		type.getField("status").setType(Integer.class);
		type.addField("createdate");
		type.getField("createdate").setType(Date.class);
		type.addField("salarydate");
		type.getField("salarydate").setType(Date.class);
		type.addField("code");
		type.getField("code").setType(String.class);
		type.addField("name");
		type.getField("name").setType(String.class);
		StoreInfo info = new StoreInfo();
		info.setTablename("hr_msalary");
		info.setKeyname(new String[] { "icode"});
		info.setSql("select * from hr_msalary where 1=2");
		//info.setParent(mainstore);// 关联主表
		//info.setLinkparentcolumns(new String[] { "icode" }); // 关联主表字段
		//info.setLinkparent_chile_columns(new String[] { "upicode" });// 关联主表字段
		  hr_msalarystore = new BaseStore<BusiObject>(type, info);
	
		  hr_msalarystore.addDefault("vprepare", Env.getEnvbcode());
		  hr_msalarystore.addDefault("createdate", DateTimeFormat.getFormat("yyyy-MM-dd").format(new Date()));
		  
		  hr_msalarystore.addBaseStoreListener( EventType.ROW_ADDED, getBasestoreListener());
		  BaseFormPanel form = new BaseFormPanel(hr_msalarystore);
		  
		  TableLayout tl = new TableLayout(4);

		  TableData td = new TableData();
		  td.setRowspan(1);
		  td.setHorizontalAlign(HorizontalAlignment.LEFT);
		  td.setVerticalAlign(VerticalAlignment.TOP);
		  td.setPadding(2);
		  form.setLayout(tl);
		  form.setHeaderVisible(false);




//		  form.add(new Label("icode:"),td);
//		   NumberField C_num1  = new NumberField(); 
//		  C_num1.setPropertyEditorType(Long.class); 
//		  C_num1.setName("icode");
//		  form.add(C_num1,td);
		  form.add(new Label("发薪编码:"),td);
		  TextField<String> C_num6  = new TextField<String>(); 
		  C_num6.setEnabled(false);
		  C_num6.setName("code");
		  form.add(C_num6,td);
		  
		  form.add(new Label("发薪名称:"),td);
		  TextField<String> C_num7  = new TextField<String>(); 
		  C_num7.setName("name");
		  form.add(C_num7,td);
		  
		  form.add(new Label("制单人:"),td);
		  TextField<String> C_num2  = new TextField<String>(); 
		  C_num2.setName("vprepare");
		  form.add(C_num2,td);
		  form.add(new Label("状态:"),td);
		   NumberField C_num3  = new NumberField(); 
		  C_num3.setPropertyEditorType(Integer.class); 
		  C_num3.setName("status");
		  form.add(C_num3,td);
		  form.add(new Label("创建日期:"),td);
		   DateField C_data4  = new DateField(); 
		  C_data4.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-M-d")); 
		  C_data4.setName("createdate");
		  form.add(C_data4,td);
		  form.add(new Label("发薪日期:"),td);
		   DateField C_data5  = new DateField(); 
		  C_data5.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-M-d")); 
		  C_data5.setName("salarydate");
		  form.add(C_data5,td);
	
	
		   form.inited(); 
		 
		   
		   d.add(form);
		   d.add(save);
		   d.show();
		   hr_msalarystore.addX();
		   d.setSize(531,200);
		   d.setButtons(Dialog.CLOSE);
//		   d.setButtons(Dialog.OKCANCEL);
		  // d.hide(d.getButtonById(Dialog.CLOSE));
		   d.setBlinkModal(true);
		   d.setModal(true);
		   d.setHideOnButtonClick(true);  
		return d;
	}
	
	int sync = 0;                                                      
	Listener<BaseEvent> defaultlistener;                               
                                                                     
	Listener<BaseEvent> getListener() {                                
		if(defaultlistener!=null)                                        
		{                                                                
			return defaultlistener;                                        
		}                                                                
                                                                     
		defaultlistener = new Listener<BaseEvent>() {                    
			public void handleEvent(BaseEvent be) {                        
				sync++;                                                      
				try {                                                        
					if (sync == 1) {                                           
						if (be.getType() == Events.Select) {                     
							if (be.getSource().equals(addto)) {  
								
								for(BusiObject bo:bcodegrid.getSelectionModel().getSelectedItems())
								{
									if(!makebcodestore.contains(bo))
									{
									makebcodestore.add(bo, false, false);
									}
									
								}
							}
							else if(be.getSource().equals(delto))
							{
								if(makebcodestore.getCurcowindex()>=0)
								{
								makebcodestore.remove(makebcodestore.getAt(makebcodestore.getCurcowindex()));
								}
								makebcodestore.commitChanges();
								makebcodestore._trySaveed();
							}
								
							else if(be.getSource().equals(savesalary))
							{
								createMakeDialog();
							}
							else if(be.getSource().equals(save))
							{
								hr_msalarystore.trySave();
								salarystore.trySave();
							}
							else if(be.getSource().equals(prequery))
							{
								createDialog();
								List<BusiObject> hr_salary_list = hr_Salary_Item_grid.getSelectionModel().getSelectedItems();
								List<BusiObject> makebcodelist = makebcodegrid.getSelectionModel().getSelectedItems();
								String salaryitemmacro ="";
								String bcodemacro ="";
								for(BusiObject bo:hr_salary_list)
								{
									salaryitemmacro +="'"+bo.get("code")+"',";
								}
								for(int i=0;i<makebcodegrid.getStore().getCount();i++)
								{
									bcodemacro +="'"+makebcodegrid.getStore().getValueBefoEdited(i, "bcode")+"',";
								}
								salaryitemmacro +="''";
								bcodemacro +="''";
								
								
								CommandSyncContainer list = new CommandSyncContainer();
								
								
								CommandSyncGetModelDatas csgmd = new CommandSyncGetModelDatas();
								csgmd.putmacro("SALARYITEM", salaryitemmacro);
								csgmd.putmacro("BCODE", bcodemacro);
								csgmd.setSqlname("salary_pre");
								list.add(csgmd);
								final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
								.create(com.base.myproject.client.tools.GreetingService.class);
								greetingService.SendCommandSync(list,new AsyncCallback<CommandSyncReturnObject>(){

									@Override
									public void onFailure(Throwable caught) {
										MessageBox.alert("错误", "网络连接失败", null);
										
									}

									@Override
									public void onSuccess(
											CommandSyncReturnObject result) {
										if(result.isB())
										{
//											BaseStore<BusiObject> salarystore = new BaseStore<BusiObject>();
											if(result.getCommandsync() instanceof CommandSyncGetModelDatas)
											{
												
												salarystore.removeAll();
												salarystore.add(((CommandSyncGetModelDatas)(result.getCommandsync())).getList(),false);
												
											}
											
											
										}
										else{
											MessageBox.alert("错误", "更新失败，错误未知！"+result.getMessage(), null);
											
										}
										
									}
							
								});
							
							}
								
						} else if (be.getType() == Events.Change) {              
							if (be.getSource().equals("输入型变量")) {         
                                                                     
							}                                                      
						} else if (be.getType() == Events.KeyUp) {               
							if (be instanceof ComponentEvent) {                    
								if (((ComponentEvent) be).getKeyCode() == 13) // 回车
								{                                                    
								}                                                    
							}                                                      
						}                                                        
					}                                                          
				} finally {                                                  
					sync--;                                                    
				}                                                            
			}                                                              
                                                                     
		};                                                               
		return defaultlistener;                                          
	}                                                                  
	private BaseStoreListener getBasestoreListener()
	{
		BaseStoreListener listener = new BaseStoreListener()
		{

			@Override
			public void BaseStoreEventHandle(final BaseStoreEvent evt) {
				
				if(evt.getEventType().equals(BaseStoreEvent.EventType.ROW_ADDED))
				{
					
					System.out.println("rowadd....");
					
					final int rowindex = evt.getBasestore().getCurcowindex();
					
					 CommandSyncContainer list  = new CommandSyncContainer();
					 CommandSyncMakeCode csmc = new CommandSyncMakeCode();
					 
					 csmc.setBeginstr("code");
					 csmc.setColumnname("code");
					 csmc.setTablename("hr_msalary");
					 list.add(csmc);
					 

					
					 final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
						.create(com.base.myproject.client.tools.GreetingService.class);
				greetingService.SendCommandSync(list, new AsyncCallback<CommandSyncReturnObject>() {
					public void onFailure(Throwable caught) {
						Window.alert("网络连接不稳定，请稍后重试！");
					}

					public void onSuccess(CommandSyncReturnObject cyro ) {
						
					
						if(cyro.isB())
						{
						evt.getBasestore().setValue(rowindex, "code", cyro.getRetrunstr());
						
					
						for(BusiObject bo:salarystore.getModels())
						{
							bo.set("upcode", cyro.getRetrunstr());
							bo.setBusistatus(SetGetValue.INSERT);
						}

						}
						else
						{
							Window.alert("分配内码时出错。");
						}
					}
				});
				}
			}

			@Override
			public void onBrowserEvent(Event event) {
				
				
			}
			
		};
		
		return listener;
	}
	
	Dialog d =null;
	void createDialog()
	{
		if(d==null)
		{
			d=new Dialog();
			d.setHeading("预查工资");
		d.add(createSalaryGrid());
		d.setButtons(Dialog.CLOSE);
		HorizontalPanel h = new HorizontalPanel();
		h.add(savesalary);
		d.setBottomComponent(h);
		
		d.setSize(491, 455);
		d.setBlinkModal(true);
		d.setModal(true);
		d.setHideOnButtonClick(true);  
		}
		d.show();
		
	}
}
